<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        ul{
            list-style: none;
           
        }
        .nav{
            position: relative;
            display: inline-block;
        }
        .nav>li>a:hover{
            background-color: #eee;
        }
        .nav ul{
            display: none;
            position: absolute;
            top: 41px;
            left: 0;
            width: 100%;
            border-left: 1px solid #fecc5b;
            border-right: 1px solid #fecc5b;
        }
        .nav ul li{
            border-bottom:  1px solid #efcc5b;
        }
        .nav ul li a:hover{
            background-color: #fff5Da;
        }
    </style>
</head>
<body>
    
   <ul class="nav">
        <li>
            <a href="#">微博</a>
            <ul>
                <li>
                    <a href="">私信</a>
                </li>
                <li>
                    <a href="">评论</a>
                </li>
                <li>
                    <a href="">@我</a>
                </li>
                
            </ul>
        </li>
        <li>
            <a href="#">微博</a>
            <ul>
                <li>
                    <a href="">私信</a>
                </li>
                <li>
                    <a href="">评论</a>
                </li>
                <li>
                    <a href="">@我</a>
                </li>
                
            </ul>
        </li>
        <li>
            <a href="#">微博</a>
            <ul>
                <li>
                    <a href="">私信</a>
                </li>
                <li>
                    <a href="">评论</a>
                </li>
                <li>
                    <a href="">@我</a>
                </li>
                
            </ul>
        </li>
        <li>
            <a href="#">微博</a>
            <ul>
                <li>
                    <a href="">私信</a>
                </li>
                <li>
                    <a href="">评论</a>
                </li>
                <li>
                    <a href="">@我</a>
                </li>
                
            </ul>
        </li>
   </ul>
   <script>
    //    1.获取元素
       let nav = document.querySelector('.nav');
       let lis = nav.children;//得到四个li
       //循环注册事件
       console.log(lis);
       for(var i = 0; i<lis.length; i++){
           lis[i].onmouseover= function(){
            this.children[1].style.display = 'block';
           }
           lis[i].onmouseout= function(){
            this.children[1].style.display = 'none';
           }

       }
   </script>
</body>
</html>